﻿@model ProductDetailsModel.AddToCartModel
@using Nop.Web.Models.Catalog;
@using Nop.Core.Domain.Orders;
<div class="add-to-cart">
    @if (Model.UpdatedShoppingCartItemId > 0)
    {
        @Html.HiddenFor(x => x.UpdatedShoppingCartItemId)
    }
    @*@if (Model.CustomerEntersPrice)
        {
            <div class="customer-entered-price">
                <div class="price-input">
                    @Html.LabelFor(model => model.CustomerEnteredPrice, new { @class = "enter-price-label" }, ":")
                    round price
                    @Html.TextBox("CustomerEnteredPrice", Convert.ToInt32(Math.Ceiling(Model.CustomerEnteredPrice)), new { @class = "enter-price-input" })
                </div>
                <div class="price-range">
                    @Model.CustomerEnteredPriceRange
                </div>
            </div>
        }*@
    @if (!Model.DisableBuyButton || !Model.DisableWishlistButton)
    {
        <div class="add-to-cart-panel">
            @Html.LabelFor(model => model.EnteredQuantity, new { @class = "qty-label" }, ":")
            @if (Model.AllowedQuantities.Count > 0)
            {
                @Html.DropDownListFor(model => model.EnteredQuantity, Model.AllowedQuantities, new { @class = "qty-dropdown form-control" })
            }
            else
            {
                @Html.TextBoxFor(model => model.EnteredQuantity, new { @class = "qty-input form-control" })

                //when a customer clicks 'Enter' button we submit the "add to cart" button (if visible)
                if (!Model.DisableBuyButton)
                {
                    <script type="text/javascript">
                        seajs.use("jquery", function ($) {
                            $(function () {
                                $("#@Html.FieldIdFor(model => model.EnteredQuantity)").keydown(function (event) {
                                    if (event.keyCode == 13) {
                                        $("#add-to-cart-button-@Model.ProductId").click();
                                        return false;
                                    }
                                });
                            });
                        });
                    </script>
                }
            }
            <div class="buttons">
                @if (!Model.DisableBuyButton)
                {
                    var addToCartText = "";
                    if (Model.UpdatedShoppingCartItemId > 0)
                    {
                        addToCartText = T("ShoppingCart.AddToCart.Update").Text;
                    }
                    else
                    {
                        addToCartText = T("ShoppingCart.AddToCart").Text;
                        if (Model.IsRental)
                        {
                            addToCartText = T("ShoppingCart.Rent").Text;
                        }
                        if (Model.AvailableForPreOrder)
                        {
                            addToCartText = T("ShoppingCart.PreOrder").Text;
                        }
                    }
                    <input type="button" id="add-to-cart-button-@Model.ProductId" class="btn btn-primary add-to-cart-button" data-addcartlink="@Url.RouteUrl("AddProductToCart-Details", new { productId = Model.ProductId, shoppingCartTypeId = (int)ShoppingCartType.ShoppingCart })" value="@addToCartText" data-productid="@Model.ProductId" />
                    //attached add 2cart /wishlist to cart product page,app("#j-product-details-page").on("click", ".add-to-cart-button"....
                }
                @if (!Model.DisableWishlistButton && Model.UpdatedShoppingCartItemId == 0)
                {
                    <input type="button" id="add-to-wishlist-button-@Model.ProductId" class="btn btn-info add-to-wishlist-button" value="@T("ShoppingCart.AddToWishlist")" data-productid="@Model.ProductId" data-addwishlistlink="@Url.RouteUrl("AddProductToCart-Details", new { productId = Model.ProductId, shoppingCartTypeId = (int)ShoppingCartType.Wishlist })" />
                }
            </div>
        </div>
    }
    @Html.Widget("productdetails_add_info", Model.ProductId)
</div>
